program main

implicit none

integer :: i,j,k,np,nx,ny
integer :: itime1,itime2,rate, nthread
real :: time, btime,etime

real, allocatable,dimension(:) :: a,b,c
real, allocatable,dimension(:,:) :: d,e

nthread=2
call omp_set_num_threads(nthread)

np=2000000
allocate(a(np),b(np),c(np))

CALL system_clock(count_rate=rate)
a=0.1
b=0.2

call SYSTEM_CLOCK(itime1)
call cpu_time(btime)
k=0
!$OMP parallel default(shared) private(i)
!$OMP do
do i=1,np
k=k+1
  if(a(i) > 0.1) then
    c(i)=a(i)+b(i)
  else
     c(i)=0.0
  endif 
enddo
!$OMP end do
!$OMP end parallel

call cpu_time(etime)
call SYSTEM_CLOCK(itime2)
time = etime - btime
print '("1D_CPU_Time = ",f12.8," seconds")',time
print '("1D_Wall_Time = ",f12.8," seconds")',real(iTime2-iTime1)/real(rate)

! 2D array
nx=2000000
ny=9
allocate(d(nx,ny),e(nx,ny))
call cpu_time(btime)
!$OMP parallel default(shared) private(i,j)
!$OMP do
do i=1,nx
  do j=1,ny
     d(i,j) = 10.0
     e(i,j) = d(i,j)*(d(i,j) +1.0)
  enddo
enddo
!$OMP end do
!$OMP end parallel

call cpu_time(etime)
call SYSTEM_CLOCK(iTime2)

time = etime - btime
print '("2D_CPU_Time = ",f12.8," seconds")',time
print '("2D_Wall_Time = ",f12.8," seconds")',real(iTime2-iTime1)/real(rate)
stop
end